home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000040_icon-group-sender _Fri Feb 11 10:19:55 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  4KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 11 Feb 1994 12:08:42 MST
  2. Date: Fri, 11 Feb 1994 10:19:55 -0600 (CST)
  3. From: Chris Tenaglia - 257-8765 <TENAGLIA@MIS.MCW.EDU>
  4. Subject: keynames
  5. To: icon-group@cs.arizona.edu
  6. Message-Id: <01H8R7KUZDDE8WXRXT@mis.mcw.edu>
  7. Organization: Medical College of Wisconsin (Milwaukee, WI)
  8. X-Vms-To: IN%"icon-group@cs.arizona.edu"
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
  11. Content-Transfer-Encoding: 7BIT
  12. Status: R
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14.  
  15.  
  16. I'm not Chinese, but I heard Chinese NewYear was this week. I don't
  17. have a game to post to commemorate the holiday, but I do have something
  18. that might turn out to be useful. I call it keyname. It's layered on
  19. getch() and is easily modified. This program/routine was written for
  20. PC, but it could probably be modified for other OSes too.
  21.  
  22. I thought it would be nice to get a name from a key strike rather than
  23. just the raw control character(s). Under VMS BASIC the inkey$ function
  24. actually returns the name of the key. Ascii characters for printables,
  25. and names like F8 or PF3 or KP5. On the PC I found that there is no
  26. distinction between numeric keypad 5 and typewriter 5. There is no
  27. disctinction between edit keypad PgDn and numeric keypad PgDn, at least
  28. as far as Icon getch() is concerned. In fact F11 and keypad 5 aren't
  29. even detected. But still this routine can make the working keys return
  30. names that can make a program more readible and easy to maintain. Enjoy!
  31.  
  32. Chris Tenaglia (System Manager) |  "The past explained,     
  33. Medical College of Wisconsin    |   the future fortold, 
  34. 8701 W. Watertown Plank Rd.     |   the present largely appologized for."
  35. Milwaukee, WI 53226             |   Organon to The Doctor
  36. (414)257-8765                   |     
  37. tenaglia@mis.mcw.edu
  38.  
  39. procedure main()                 # this main() tests the routine below
  40.   repeat
  41.     {
  42.     k := getch()
  43.     if k == "#" then break               # permit clean escape
  44.     if k == "\000" then k ||:= getch()
  45.     write(image(k)," = ",keyname(k))
  46.     }
  47.   end
  48.  
  49. procedure keyname(str)
  50.   static  keys
  51.   initial {
  52.           keys := table("ANY")
  53.           keys["\000;"] := "F1"
  54.           keys["\000<"] := "F2"
  55.           keys["\000="] := "F3"
  56.           keys["\000>"] := "F4"
  57.           keys["\000?"] := "F5"
  58.           keys["\000@"] := "F6"
  59.           keys["\000A"] := "F7"
  60.           keys["\000B"] := "F8"
  61.           keys["\000C"] := "F9"
  62.           keys["\000D"] := "F10"
  63.           keys["\000\373"] := "F12"
  64.  
  65.           keys["\000H"] := "UPARROW"
  66.           keys["\000P"] := "DOWNARROW"
  67.           keys["\000M"] := "RIGHTARROW"
  68.           keys["\000K"] := "LEFTARROW"
  69.           keys["\000I"] := "PAGEUP"
  70.           keys["\000Q"] := "PAGEDOWN"
  71.           keys["\000G"] := "HOME"
  72.           keys["\000O"] := "END"
  73.           keys["\000R"] := "INSERT"
  74.           keys["\000S"] := "DELETE"
  75.           
  76.           keys["\e"]    := "ESCAPE"
  77.           keys["\001"]  := "CTRL_A"
  78.           keys["\002"]  := "CTRL_B"
  79.           keys["\003"]  := "CTRL_C"
  80.           keys["\004"]  := "CTRL_D"
  81.           keys["\005"]  := "CTRL_E"
  82.           keys["\006"]  := "CTRL_F"
  83.           keys["\007"]  := "BELL"
  84.           keys["\010"]  := "BACKSPACE"
  85.           keys["\011"]  := "TAB"
  86.           keys["\012"]  := "LINEFEED"
  87.           keys["\013"]  := "CTRL_K"
  88.           keys["\014"]  := "FORMFEED"
  89.           keys["\015"]  := "RETURN"
  90.           keys["\016"]  := "CTRL_N"
  91.           keys["\017"]  := "CTRL_O"
  92.           keys["\020"]  := "CTRL_P"
  93.           keys["\021"]  := "CTRL_Q"
  94.           keys["\022"]  := "CTRL_R"
  95.           keys["\023"]  := "CTRL_S"
  96.           keys["\024"]  := "CTRL_T"
  97.           keys["\025"]  := "CTRL_U"
  98.           keys["\026"]  := "CTRL_V"
  99.           keys["\027"]  := "CTRL_W"
  100.           keys["\030"]  := "CTRL_X"
  101.           keys["\031"]  := "CTRL_Y"
  102.           keys["\032"]  := "CTRL_Z"
  103.           }
  104.   return keys[str]
  105.   end
  106.  
  107.